package com.polaris.server.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.polaris.server.dto.TripQueryParam;
import com.polaris.server.pojo.TrafficTrip;
import com.polaris.server.mapper.TrafficTripMapper;
import com.polaris.server.service.ITrafficTripService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author polaris
 * @since 2021-06-02
 */
@Service
public class TrafficTripServiceImpl extends ServiceImpl<TrafficTripMapper, TrafficTrip> implements ITrafficTripService {

    private final TrafficTripMapper tripMapper;

    public TrafficTripServiceImpl(TrafficTripMapper tripMapper) {
        this.tripMapper = tripMapper;
    }

    /**
     * 获取trip的list
     *
     * @param queryParam
     * @param page
     * @return
     */
    @Override
    public IPage<TrafficTrip> list(TripQueryParam queryParam, Page<TrafficTrip> page) {
        if (StringUtils.hasText(queryParam.toString())){
            QueryWrapper<TrafficTrip> queryWrapper = new QueryWrapper<>();
            Map<String, Object> beanToMap = BeanUtil.beanToMap(queryParam, true, false);
            queryWrapper.allEq(beanToMap,false);
            return tripMapper.selectPage(page,queryWrapper);
        }
        return null;
    }
}
